<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <!-- import CSS -->
    <link rel="stylesheet" href="https://cdn.staticfile.org/element-ui/2.15.9/theme-chalk/index.css">
</head>
<body>
<div id="app">
    <el-page-header style="background-color: #0096dc;color: white;line-height: 60px"
                    @back="goBack" content="修改文章页面">
    </el-page-header>
    <el-card style="width: 600px;height: 800px;margin: 0 auto">
        <el-form label-width="80px">
            <el-form-item label="文章标题"><el-input type="text" v-model="a.title"></el-input></el-form-item>
            <el-form-item label="文章内容"><el-input type="text" v-model="a.content"></el-input></el-form-item>
            <el-form-item label="状态"><el-input type="text" v-model="a.status"></el-input></el-form-item>
            <el-form-item label="文章分类" >
                <el-select placeholder="请选择分类" v-model="a.articleCategoryId">
                    <el-option v-for="a in arr" :label="a.title" :value="a.id"></el-option>
                </el-select>
            </el-form-item>
            <el-form-item>
                <el-button type="success" @click="update()">修改文章</el-button>
            </el-form-item>
        </el-form>
    </el-card >


</div>
</body>
<!--引入axios和vue框架文件-->
<script src="https://cdn.bootcdn.net/ajax/libs/axios/0.21.1/axios.min.js"></script>

<!-- import Vue before Element -->
<script src="https://cdn.staticfile.org/vue/2.6.14/vue.min.js"></script>
<!-- import JavaScript -->
<script src="https://cdn.staticfile.org/element-ui/2.15.9/index.min.js"></script>
<script>
    let v = new Vue({
        el: '#app',
        data: function () {
            return {
                arr:[],
                a:{title:"",content:"",status:"",
                    articleCategoryId:""},
            }

        },
        methods: {
            update() {
                //发请求
                axios.post("/article/update", v.a).then(function (response) {
                    location.href = "/admin.html";//回到后台管理页面
                })
            },
            goBack() {
                //返回上一页面
                history.back();
            },

            created: function () {
                //发请求获取所有分类页面
                axios.get("/articleCategory/select").then(function (response) {
                    v.arr = response.data;
                })
                //发出请求获取文章详情信息
                axios.get("/article/selectUpdateById" + location.search).then(function (response) {
                    v.p = response.data;
                })
            }
        }
    })

</script>
</html>